public class 二叉树的最小深度 {
    
    public static int min;
    public static int path;

    public int minDepth(TreeNode root) {

        min = Integer.MAX_VALUE;
        path = 0;
        dfs(root);
        return min == Integer.MAX_VALUE ? 0 : min;
    }

    public void dfs(TreeNode root) {
        if(root == null){
            return;
        }
        path++;
        if(root.left == null && root.right == null){
            min = Math.min(min,path);
            path--;
            return;
        }
        dfs(root.left);
        dfs(root.right);
        path--;

    }
}
